/*jslint sloppy: true */
/*global require */
var LM = require('../global');
require('./style.less');
require('./header.html');
require('./footer.html');

LM.controller('Main', function ($scope, $routeParams, $location, $window, $element) {
	var qC = $scope.queryConfig = {
		isShow: false,
		keyword: ''
	}, nC = $scope.navConfig = {
		type: null,
		href: '#/'
	};

	qC.clear = function () {
		this.keyword = '';
		return this;
	};
	qC.setActive = function (state) {
		this.isShow = !!state;
		return this;
	};

	nC.setHref = function (href) {
		this.href = href;
		return this;
	};
	nC.setType = function (type) {
		this.type = type;
		return this;
	};

	$scope.logout = function () {
		$scope.account.$logout(null, function () {
			$location.url('/');
		});
	};
	$scope.historyBack = function () {
		$window.history.back();
	};

	$scope.$on('$routeChangeStart', function () {
		$window.scrollTo(0, 0);
	});

	$scope.captchaTime = Date.now();
	$scope.getNow = function () {
		$scope.captchaTime = Date.now();
	};

	$scope.goBack = function (url) {
		console.log(url);
		$location.path(url.substr(2));
	};
});
